--[[/**
-- * 
 * 阿莉克希亚 大招 平均回复 专武升级后的效果
 * 该脚本判断 英雄学会了哪个 技能加对应的buff
 * 再附带一个 溢出参数
-- *
-- */]]

---@class BuffEffect398100 : BaseBuffEffect
BuffEffect398100 = ClientFight.CreateClass("BuffEffect398100", ClientFight.BaseBuffEffect)
local t = BuffEffect398100
t.BUFF_EFFECT_398100_OVERLAP = "BUFF_EFFECT_398100_OVERLAP";
---@param fight Fight
---@param buff FighterBuff
function t:add(fight, buff)
    local fighter = buff.target;
    local source = buff.source;
    local fightTeam = fight.teams[fighter.teamIndex];
    local peopleAmount = 0;

    local effectValues = buff.buffBean.f_BuffEffectValue;
    local shape = Rectangle2.New(effectValues[1], effectValues[2]);
    local targets = {};
    for k, f in pairs(fightTeam.fighters) do
        if (f:isSummons() and not f.isRealSummons()) then
            goto continue;
        end
        if (f:isDie()) then
            goto continue;
        end
        if (not DistanceUtil.overlap(fighter.position, shape, f.position, f.shape)) then
            goto continue;
        end
        table.insert(targets, f);
        peopleAmount = peopleAmount + 1;
        :: continue ::
    end
    local logPeopleAmount = peopleAmount;
    local buffModelId = 0;
    for i = 4, table.getn(effectValues), 2 do
        if (i + 2 > table.getn(effectValues)) then
            break ;
        end
        local b = containsSkillId(effectValues[i], source);
        if (b) then
            buffModelId = effectValues[i + 1];
            break ;
        end
    end
    if (buffModelId < 0) then
        return IBuffEffect.FAIL;
    end
    source.parametersByObject[BuffEffect392100.BUFF_EFFECT_392100_FIGHTER_AMOUNT] = peopleAmount;
    source.parametersByObject[t.BUFF_EFFECT_398100_OVERLAP] = effectValues[3];
    SkillRoleMgr.savePathFile(string.format("[%s][EFFECT]Fighter %s  Buff%s 大招平均回复,有%s人",
            fight.frame, fighter.fighterId, buff.modelId, logPeopleAmount
    ));
    for k, _fighter in pairs(targets) do
        BuffManager.addBuff(fight, buff.skill, source, _fighter, false, buffModelId, 1);
    end
    return ClientFight.BaseBuffEffect.add(self, fight, buff);
end

t.New()